package com.start.admin.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.start.admin.entity.StartSysUserManageDept;
import com.start.admin.service.StartSysUserManageDeptService;
import com.start.admin.vo.StartSysUserManageDeptVo;
import com.start.common.api.Result;
import com.start.common.dataRule.DataQueryConstructor;
import com.start.core.annotations.RegisterMenu;
import com.start.core.annotations.RegisterPermission;
import com.start.core.annotations.StartLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
@RestController
@RequestMapping("/start/sysUserManageDept")
@RegisterMenu(value = "部门管理", systemCode = "sys:dept", component = "views/sys/dept/index", path = "/dept/index")
public class StartSysUserManageDeptController {
    private final static String LOG_TITLE = "部门负责人管理";
    @Autowired
    private StartSysUserManageDeptService manageDeptService;

    @GetMapping("/list")
    public Result<?> list(Page<StartSysUserManageDeptVo> page, StartSysUserManageDeptVo entity) {
       QueryWrapper<StartSysUserManageDeptVo> lambdaQuery = DataQueryConstructor.createEntity(StartSysUserManageDeptVo.class);
        return Result.ok(manageDeptService.pageUserManage(page,lambdaQuery));
    }


    @PostMapping("/add")
    @StartLog(value = LOG_TITLE, action = "添加-部门负责人")
    @PreAuthorize("@pas.hasPermission('sys:user:manage:dept:add')")
    @RegisterPermission(value = "sys:user:manage:dept:add", name = "添加-部门负责人")
    public Result add(@RequestBody StartSysUserManageDept entity) {
        manageDeptService.save(entity);
        return Result.ok();
    }

    @PutMapping("/updateById")
    @StartLog(value = LOG_TITLE, action = "修改-部门负责人")
    @PreAuthorize("@pas.hasPermission('sys:user:manage:dept:edit')")
    @RegisterPermission(value = "sys:user:manage:dept:edit", name = "修改-部门负责人")
    public Result updateById(@RequestBody StartSysUserManageDept entity) {
        manageDeptService.updateById(entity);
        return Result.ok();
    }

    @GetMapping("/getById/{id}")
    @StartLog(value = LOG_TITLE, action = "查看-部门负责人")
    @PreAuthorize("@pas.hasPermission('sys:user:manage:dept:info')")
    @RegisterPermission(value = "sys:user:manage:dept:info", name = "查看-部门负责人")
    public Result getById(@PathVariable("id") String id) {
        return Result.ok(manageDeptService.getById(id));
    }


    @DeleteMapping("deleteById/{id}")
    @StartLog(value = LOG_TITLE, action = "删除-部门负责人")
    @PreAuthorize("@pas.hasPermission('sys:user:manage:dept:delete')")
    @RegisterPermission(value = "sys:user:manage:dept:delete", name = "删除-部门负责人")
    public Result<?> deleteById(@PathVariable("id") String id) {
        manageDeptService.removeById(id);
        return Result.ok();
    }
}
